package net.optix.ip.commands
{
	import com.adobe.cairngorm.business.Responder;
	import com.adobe.cairngorm.commands.Command;
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import mx.collections.ArrayCollection;
	
	import net.optix.ip.business.*;
	import net.optix.ip.events.GetTrackInventionsByFirmEvent;
	import net.optix.ip.model.ModelLocator;
	import net.optix.ip.vo.FirmInventionVO;
	import net.optix.ip.vo.TrackVO;
	

	public class GetTrackInventionsByFirmCommand implements Command, Responder
	{
		// attributes ============================
		private var model : ModelLocator = ModelLocator.getInstance();


		// functions ============================
		public function execute( event:CairngormEvent ) : void
		{
			var myEvent:GetTrackInventionsByFirmEvent	=	GetTrackInventionsByFirmEvent(event);
			var delegate:InventionDelegate	=	new InventionDelegate();
			delegate.getTrackInventionsByFirm(this,myEvent.clientID);
		}
		
		//----------------------------------------------------------------------------
		public function onResult( event : * = null ) : void
		{
			trace(event.result);
			try
			{
				var result:XML		=	event.result;
				
				var tracks:ArrayCollection	=	TrackVO.purseTracks(result);
				
				model.tracks	=	tracks;
				
				var firms:ArrayCollection	=	FirmInventionVO.purseFirst(tracks);
				model.tracksByFirm	=	firms;
				/*for(var i:int=0 ; i<firms.length; i++)
				{
					var firm:FirmInventionVO	=	FirmInventionVO(firms[i]);
					trace(firm.numInventionAb+ "   firm.numInventionAb");
					trace(firm.numInventionIss+ "   firm.numInventionIss");
					trace(firm.sumFillingCost+ "   firm.sumFillingCost");
					trace(firm.sumResponseCost+ "   firm.sumResponseCost");
					//trace(firm.numInventionAb+ "   firm.numInventionAb");
					//trace(firm.numInventionAb+ "   firm.numInventionAb");
				}*/
			}
			catch(error:Error)
			{
				trace(error.getStackTrace()+"get trackinventions byf irm");
			}
		}
		
		//----------------------------------------------------------------------------
		public function onFault( event : * = null ) : void
		{
			trace(event.fault);
		}

	}
}